package com.mxpio.erp.hr.service.impl;

import com.mxpio.erp.common.hr.entity.Contract;
import com.mxpio.erp.common.hr.entity.Employee;
import com.mxpio.erp.common.hr.service.ContractService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

;


@Service
public class ContractServiceImpl extends BaseServiceImpl<Contract> implements ContractService {

        @Override
        @Transactional(rollbackFor = Exception.class)
        public Contract doSave(Contract contract) {

            //1. 合同落库
            this.save(contract);

            //2. 更新员工表中的合同开始结束时间
            Employee employee = JpaUtil.linq(Employee.class).equal("nameCode", contract.getNameCode()).findOne();

            employee.setDateStartContract(contract.getDateStartContract());
            employee.setDateEndContract(contract.getDateEndContract());

            JpaUtil.update(employee);

            return contract;
        }

}